package com.example.picturebacked.api.imagesearch;

import com.example.picturebacked.api.imagesearch.model.ImageSearchResult;
import com.example.picturebacked.api.imagesearch.sub.GetImageFirstUrlApi;
import com.example.picturebacked.api.imagesearch.sub.GetImageListApi;
import com.example.picturebacked.api.imagesearch.sub.GetImagePageUrlApi;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Autheor LBT
 * 一个一个获取麻烦，不方便调用，直接封装在图片搜索API类中
 */
@Slf4j
public class ImageSearchApiFacade {
    /**
     * 搜索图片
     */
    public static List<ImageSearchResult> searchImage(String imageUrl) {
        String imagePageUrl = GetImagePageUrlApi.getImagePageUrl(imageUrl);
        String imageFirstUrl = GetImageFirstUrlApi.getImageFirstUrl(imagePageUrl);
        List<ImageSearchResult> imageList = GetImageListApi.getImageList(imageFirstUrl);
        return imageList;
    }

    /**
     * 测试功能
     */
    public static void main(String[] args) {
        String imageUrl = "https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1280&q=80";
        List<ImageSearchResult> imageSearchResults = searchImage(imageUrl);
        System.out.println("结果列表" + imageSearchResults);
    }
}



















